const { override, fixBabelImports, addLessLoader, addWebpackAlias } = require('customize-cra');
const path = require('path');
// const webpack = require('webpack')
// const AddAssetHtmlPlugin = require('add-asset-html-webpack-plugin')
// const px2rem = require('postcss-px2rem-exclude');
// px2rem({remUnit:75,exclude: /node_modules/i}),

const CompressionWebpackPlugin = require('compression-webpack-plugin');

const addCustomize = () => config => {
    if (process.env.NODE_ENV === 'production') {
        // 关闭sourceMap
        config.devtool = false;
        // 配置打包后的文件位置
        // config.output.path = resolve('dist');
        // config.output.publicPath = './';
        // 添加js打包gzip配置
        config.plugins.push(
            new CompressionWebpackPlugin({
                test: /\.js$|\.css$/,
                threshold: 1024,
            }),
        );
        config.entry.unshift("whatwg-fetch", "babel-polyfill"/*, "./src"*/);
    }
    return config;
}

// dev 配置 暂时不使用
// const devServerConfig = () => config => {
//     config.devServer.proxy = {
//         '/': {
//                 target: 'http://bydbm.dev.colyst.cn/',
//                 changeOrigin: true,
//             }
//     }
//     return config;
// }


process.env.GENERATE_SOURCEMAP = "false";

module.exports = override(
    fixBabelImports('import', { // Ant 按需
        libraryName: 'antd',
        libraryDirectory: 'es',
        style: true,
    }),

    addWebpackAlias({ // 路径别名
        '@': path.resolve(__dirname, 'src'),
    }),

    addLessLoader({ // less
        javascriptEnabled: true,
        modifyVars: {
            '@primary-color': '#1DA57A'
        },
    }),

    addCustomize()
);